#include "headfile.h"

int main()
{
    printf("Hello World !\n");
    int fd1;
    fd1 = open("./testApp.txt", O_RDWR | O_CREAT | O_EXCL, 0664);
    if(-1 == fd1){
        perror("Creat error");
        close(fd1);
        exit(-1);
    }
    else{
        printf("Creat Successful !\n");
    }

    int ret;
   
    ret = lseek(fd1,0,SEEK_SET);
    if(-1 == ret){
        perror("Set error");
        close(fd1);
        exit(-1);
    }
    else{
        printf("Set Successful !\n");
    }
 
    ret = write(fd1,"Hello World,Hello Linux !",26);
	if(-1 == ret){
		perror("Write error");
		close(fd1);
		exit(-1);
	}
    else{
	    printf("Write :%d bytes OK !\n",ret);
    }

    ret = lseek(fd1,5,SEEK_SET);
    if(-1 == ret){
        perror("Set error");
        close(fd1);
        exit(-1);
    }
    else{
        printf("Set Successful !\n");
    }

    char buff[50] ={0};
    ret = read(fd1,buff,50);
    if(-1 == ret){
        perror("Read error");
        close(fd1);
        exit(-1);
    }
    else{
        printf("Read Successful ! byte:%d\n",ret);
        printf("String : %s\n",buff);
    }

    close(fd1);    
    
    return 0;
}






